//package com.kingstar.ceres.helper;
//
//import lombok.extern.slf4j.Slf4j;
//import org.smartboot.socket.MessageProcessor;
//import org.smartboot.socket.StateMachineEnum;
//import org.smartboot.socket.transport.AioSession;
//import org.smartboot.socket.transport.WriteBuffer;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.Map;
//import java.util.concurrent.ConcurrentHashMap;
//
//@Slf4j
//@Component
//public class PushServerProcessorMessage implements MessageProcessor<String> {
//
//    @Autowired
//    private InitAndSendHelper initAndSendHelper;
////    private static final Logger LOGGER = LoggerFactory.getLogger(PushServerProcessorMessage.class);
//
//    private Map<String, AioSession> sessionMap = new ConcurrentHashMap<>();
//
//    private String name;
//
//    public Map<String, AioSession> getSessionMap() {
//        return sessionMap;
//    }
//
//    public PushServerProcessorMessage() {
//    }
//
//    public PushServerProcessorMessage(String name) {
//        this.name = name;
//    }
//
//    @Override
//    public void process(AioSession session, String msg) {
//        log.info("{} Receive msg:{}",name,msg);
////        byte[] bytes = msg.getBytes();
////        sessionMap.values().forEach(onlineSession -> {
////            if (session == onlineSession) {
////                return;
////            }
////            WriteBuffer writeBuffer = onlineSession.writeBuffer();
////            try {
////                log.info("{} Push msg to ReceiverClient:{}",name, onlineSession.getSessionID());
////                writeBuffer.writeInt(bytes.length);
////                writeBuffer.write(bytes);
////                writeBuffer.flush();
////            } catch (Exception e) {
////                log.error("{} push msg error:{}",name,e.getMessage());
////            }
////        });
//    }
//
//    @Override
//    public void stateEvent(AioSession session, StateMachineEnum stateMachineEnum, Throwable throwable) {
//        switch (stateMachineEnum) {
//            case NEW_SESSION:
//                log.info("与客户端:{} 建立连接", session.getSessionID());
//                sessionMap.put(session.getSessionID(), session);
//                if (sessionMap.size()==1){
//                    initAndSendHelper.init();
//                }
//                break;
//            case SESSION_CLOSED:
//                log.info("断开客户端连接: {}", session.getSessionID());
//                sessionMap.remove(session.getSessionID());
//                break;
//            default:
//        }
//    }
//
//    public void sendMsg(String msg){
//        byte[] bytes = msg.getBytes();
//        sessionMap.values().forEach(onlineSession -> {
//            WriteBuffer writeBuffer = onlineSession.writeBuffer();
//            try {
//                log.info("Push msg to ReceiverClient:{}", onlineSession.getSessionID());
//                writeBuffer.writeInt(bytes.length);
//                writeBuffer.write(bytes);
//                writeBuffer.flush();
//            } catch (Exception e) {
//                log.error("{} push msg error:{}",name,e.getMessage());
//            }
//        });
//    }
//}